package com.kyxx.topics.view;

import android.app.AlertDialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.kyxx.topics.BaseApp;
import com.kyxx.topics.R;
import com.kyxx.topics.utils.StringUtil;


/**
 * 一些ui中Dialog中的使用
 *
 * @author bin
 */
public class UIDialog {
    public static AlertDialog dialog;

    /**
     * 3按键按钮dialog
     */
    public static void ForThreeBtn(Context context, String[] showtxt,
                                   OnClickListener lisener) {
        dialog = new AlertDialog.Builder(context, R.style.Translucent_NoTitle).create();
        dialog.show();
        Window window = dialog.getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT; // 设置宽度
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setGravity(Gravity.BOTTOM);
        window.setAttributes(lp);
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.dialog_three_picture);

        Button m_btn_1 = (Button) window.findViewById(R.id.dialog_modif_1);
        Button m_btn_2 = (Button) window.findViewById(R.id.dialog_modif_2);
        Button m_btn_3 = (Button) window.findViewById(R.id.dialog_modif_3);

        m_btn_1.setText(showtxt[0]);
        m_btn_2.setText(showtxt[1]);
        m_btn_3.setText(showtxt[2]);


        m_btn_1.setOnClickListener(lisener);
        m_btn_2.setOnClickListener(lisener);
        m_btn_3.setOnClickListener(lisener);
    }

    /**
     * 3按键按钮dialog
     */
    public static void ForFourBtn(Context context, String[] showtxt,
                                  OnClickListener lisener) {
        dialog = new AlertDialog.Builder(context, R.style.Translucent_NoTitle).create();
        dialog.show();
        Window window = dialog.getWindow();
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.FILL_PARENT; // 设置宽度
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setGravity(Gravity.BOTTOM);
        window.setAttributes(lp);
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.dialog_four_picture);

        Button m_btn_1 = (Button) window.findViewById(R.id.dialog_modif_5);
        Button m_btn_2 = (Button) window.findViewById(R.id.dialog_modif_2);
        Button m_btn_3 = (Button) window.findViewById(R.id.dialog_modif_3);
        Button m_btn_4 = (Button) window.findViewById(R.id.dialog_modif_4);

        m_btn_1.setText(showtxt[0]);
        m_btn_2.setText(showtxt[1]);
        m_btn_3.setText(showtxt[2]);
        m_btn_4.setText(showtxt[3]);
        if (StringUtil.isEmpty(BaseApp.getModel().getMobile())) {
            m_btn_1.getResources().getColor(R.color.smssdk_gray);
            m_btn_1.setOnClickListener(null);
        } else {
            m_btn_1.setOnClickListener(lisener);
        }

        m_btn_2.setOnClickListener(lisener);
        m_btn_3.setOnClickListener(lisener);
        m_btn_4.setOnClickListener(lisener);
    }

    /**
     * 关闭dialog
     */
    public static void closeDialog() {
        if (dialog == null || !dialog.isShowing()) {
            return;
        }
        dialog.dismiss();

    }
}
